package inc.zhugastrov.ui.resourses;

import inc.zhugastrov.users.Account;
import inc.zhugastrov.users.Position;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

public class UserViewTableModel extends AbstractTableModel {
	private final int NAME = 0;
	private final int SURNAME = 1;
	private final int POSITION = 2;
	private Vector<Account> dataVector;
	private String[] columnNames;

	public UserViewTableModel(String[] columnNames) {
		this.columnNames = columnNames;
		dataVector = new Vector<Account>();
	}

	public boolean isCellEditable(int row, int column) {
		return false;
	}
	
	public boolean isCellSelected(int row, int column) {
		return false;
	}

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public int getRowCount() {
		return dataVector.size();
	}

	public String getColumnName(int column) {
		return columnNames[column];
	}

	@Override
	public Object getValueAt(int row, int colunm) {
		Account account = (Account) dataVector.get(row);
		switch (colunm) {
		case NAME:
			return account.getName();
		case SURNAME:
			return account.getSurname();
		case POSITION:
			return account.getPosition().toString();
		default:
			System.out.println("WATA FUCK????");
			return new Object();
		}

	}

	public Account getRow(int row){
		return (Account) dataVector.get(row);
	}
	
	public void addRow(Account newAccount) {
		dataVector.add(newAccount);
		fireTableRowsInserted(dataVector.size() - 1, dataVector.size() - 1);
	}

	public void addEmptyRow() {
		Account acc = new Account();
		acc.setName("");
		acc.setSurname("");
		acc.setPosition(Position.SELLER);
		dataVector.add(acc);
	}
}
